package com.ywf.corebase.framework.config;


import com.ywf.corebase.framework.interceptor.HeaderParamsCheckInterceptor;
import com.ywf.corebase.framework.interceptor.ResponseResultInterceptor;
import com.ywf.corebase.framework.interceptor.TokenInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ClassName:JwtInterceptorConfig
 * Package:com.ywf.myproject.common.interceptor
 * Description:
 *
 * @Date:2021/3/2 21:06
 * @Author:YWF
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    final static Logger logger = LoggerFactory.getLogger(InterceptorConfig.class);

    final static String pathPatterns = "/*/**";

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        logger.info("===================进入拦截器处理业务=========================");
        registry.addInterceptor(responseResultInterceptor()).addPathPatterns(pathPatterns);
        registry.addInterceptor(headerParamsCheckInterceptor()).addPathPatterns(pathPatterns);
        registry.addInterceptor(tokenInterceptor()).addPathPatterns(pathPatterns);
    }

    @Bean
    public ResponseResultInterceptor responseResultInterceptor(){
        return new ResponseResultInterceptor();
    }

    @Bean
    public HeaderParamsCheckInterceptor headerParamsCheckInterceptor(){ return new HeaderParamsCheckInterceptor(); }

    @Bean
    public TokenInterceptor tokenInterceptor(){
        return new TokenInterceptor();
    }
}
